using System;
using Sharepoint.Console.Commands;

namespace SharePoint.Console.Site
{
    class Navigate: BaseCommande
    {
        public override string ShortHelp
        {
            get
            {
                return "Navigate to a site";
            }
        }

        public override string LongHelp
        {
            get
            {
                return "Navigate to a site using this an url. Site must be into the connected sites collection.\nConnection to the site collection is made by Connect statement.";
            }
        }

        public override string Syntax
        {
            get
            {
                return "Navigate 'site url'";
            }
        }

        public override string Execute(string[] args)
        {
            if (args.Length != 2) return string.Format("Invalide syntax. Use {0}", Syntax);

            string webUrl = args[1];

            if (this.SharepointConnection.Site != null)
            {
                try
                {
                    this.SharepointConnection.Web = this.SharepointConnection.Site.OpenWeb(webUrl);

                    return string.Format("Active site is {0}", webUrl);
                }

                catch
                {
                    return "Web site doesn't exist";
                }
            }
            else { return "No opened connection"; }
        }

    }
}
